package com.cn.ant.modules.volunteer.service;

import com.cn.ant.common.persistence.Page;
import com.cn.ant.common.service.BaseService;
import com.cn.ant.modules.volunteer.dao.VolunteerSchoolDao;
import com.cn.ant.modules.volunteer.entity.VolunteerSchool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 * 学校与志愿组合Service
 * @author 黄根华
 * @version 2015-10-11
 */
@Service
@Transactional(readOnly = true)
public class VolunteerSchoolService extends BaseService {

    @Autowired
	private VolunteerSchoolDao volunteerSchoolDao;

	public VolunteerSchool get(String id) {
		return volunteerSchoolDao.get(id);
	}
	
	public List<VolunteerSchool> findList(VolunteerSchool volunteerSchool) {
		return volunteerSchoolDao.findList(volunteerSchool);
	}
	
	public Page<VolunteerSchool> findPage(Page<VolunteerSchool> page, VolunteerSchool volunteerSchool) {
	    volunteerSchool.setPage(page);
        page.setList(volunteerSchoolDao.findList(volunteerSchool));
        return page;
	}
	
	@Transactional(readOnly = false)
	public void save(VolunteerSchool volunteerSchool) {
	    if (volunteerSchool.getIsNewRecord()) {
            volunteerSchool.preInsert();
            volunteerSchoolDao.insert(volunteerSchool);
        } else {
            volunteerSchool.preUpdate();
            volunteerSchoolDao.update(volunteerSchool);
        }
	}

	/**
	 * 批量插入
	 * @param schoolList
	 */
	@Transactional(readOnly = false)
	public void batchSave(List<VolunteerSchool> schoolList) {
		if (schoolList != null && schoolList.size() > 0) {
			for (int i = 0; i < schoolList.size(); i++) {
				schoolList.get(i).preInsert();
			}
			volunteerSchoolDao.batchInsert(schoolList);
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(VolunteerSchool volunteerSchool) {
		volunteerSchoolDao.delete(volunteerSchool);
	}
	
}